package edu.nwpu.zya.coreops.modules.monitor.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.nwpu.zya.coreops.common.utils.PageUtils;
import edu.nwpu.zya.coreops.common.utils.Query;

import edu.nwpu.zya.coreops.modules.monitor.dao.MetricDao;
import edu.nwpu.zya.coreops.modules.monitor.entity.MetricEntity;
import edu.nwpu.zya.coreops.modules.monitor.service.MetricService;
import org.springframework.util.StringUtils;


@Service("metricService")
public class MetricServiceImpl extends ServiceImpl<MetricDao, MetricEntity> implements MetricService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<MetricEntity> queryWrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(params.get("type"))){
            queryWrapper.eq("type",Integer.parseInt((String) params.get("type")));
        }
        if(!StringUtils.isEmpty(params.get("name"))){
            queryWrapper.like("name",(String) params.get("name"));
        }

        IPage<MetricEntity> page = this.page(
                new Query<MetricEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    /**
     * 根据实例ID获取
     * @param instanceId
     * @return
     */
    @Override
    public List<MetricEntity> getEcsMetricsByInstanceId(String instanceId) {
        return this.baseMapper.getEcsMetricsByInstanceId(instanceId);
    }

    @Override
    public List<MetricEntity> getRdsMetricsByInstanceId(String instanceId) {
        return this.baseMapper.getRdsMetricsByInstanceId(instanceId);
    }

    @Override
    public List<MetricEntity> getAppMetricsByInstanceId(String instanceId) {
        return this.baseMapper.getAppMetricsByInstanceId(instanceId);
    }

}